package com.hqyj.springBoot.modules.test.controller;

import com.hqyj.springBoot.modules.test.entity.Country;
import com.hqyj.springBoot.modules.test.service.CountryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController //相当于@RequestBody + @Controller
@RequestMapping("/api")
public class CountryController {

    //注入对象
    @Autowired
    private CountryService countryService;

    /**
     *127.0.0.1/api/country/522 ---- get
     */
    @GetMapping("/country/{countryId}")
    public Country getCountryByCountryId(@PathVariable int countryId){
        return countryService.getCountryByCountryId(countryId);
    }

    /**
     * 127.0.0.1/api/country?countryName=China&localCountryName=Zhongquo ---- get
     */
    @GetMapping("/country")
    public Country getCountryByCountryNameAndLocalCountryName(@RequestParam String countryName,
                                                              @RequestParam String localCountryName){
        return countryService.getCountryByCountryNameAndLocalCountryName(countryName,localCountryName);
    }
}
